<template>
  <div>
    <el-card class="box-card">
      <span><i class="iconfont icon-dingdan1 icon"> </i>产品分类数据列表</span>
      <el-button style="float: right; padding: 3px" type="primary" @click="goCateAddPage"
        >添加</el-button
      >
      <el-button
        style="float: right; padding: 3px; margin-right: 5px"
        type="primary"
        v-if="parentId != 0"
        @click="goBackLevel"
        >返回上级节点</el-button
      >
    </el-card>
     <el-table   :data="cateList" border   style="width: 100%">
    <el-table-column prop="id" label="编号"   width="100">
    </el-table-column>
    <el-table-column  prop="name"  label="分类名称"    width="100">
    </el-table-column>
    <el-table-column  prop="level"  label="级别" width="100">
      <template slot-scope="scope">
          {{ scope.row.level }}
        </template>
    </el-table-column>
     <el-table-column  prop="product_count"  label="商品数量" width="100">
    </el-table-column>
     <el-table-column  prop="product_unit"  label="数量单位" align="center">
    </el-table-column>
    <el-table-column  prop=" show_status"  label="是否显示" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.show_status"
            :active-value="1"
            :inactive-value="0"
          >
          </el-switch>
        </template>
    </el-table-column>
    <el-table-column  prop="sort"  label="排序" align="center">
    </el-table-column>
    <el-table-column  prop="address"  label="设置" align="center">
         <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="showNextLevel(scope.row.id)" 
          :disabled="scope.row.level==1">查看下级</el-button>
        </template>
    </el-table-column>
    <el-table-column  prop="address"  label="操作" align="center">
      <template slot-scope="scope" @click="delFun(scope.row.id)">
          <el-button size="small" 
            >编辑</el-button
          >
          <el-button type="danger" size="small" @click="delFun(scope.row.id)"
            >删除</el-button
          >
        </template>

    </el-table-column>
  </el-table>

  <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="listQuery.pageNum"
      :page-sizes="[2, 5, 10, 15]"
      :page-size="listQuery.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { fenLei} from "@/api/product";
//import axios from "axios";
export default {
  name:"productCate",
  data:function(){
    return {
      cateList:[],
    //  classiFication:[],
      listQuery:{
          pageNum:1,
          pageSize:5,
      },
      total:0,
      parentId:0,
    };
  },
  methods:{ 
   
    handleSizeChange(val){
     console.log("修改每页显示的条数 触发了", val);
     this.listQuery.pageSize = val;
     this.listQuery.pageNum = 1;
     this.getFenLieList();
   },
   handleCurrentChange(val){
     console.log("修改当前页的页码 触发了", val);
     this.listQuery.pageNum = val;
     this.getFenLieList();
   },
    async getFenLieList(){
      const res = await  fenLei(this.listQuery,this.parentId);
      console.log(res);
      this.cateList = res.data
      this.total = res.total;
    },
  //   filters: {
  //   jibeiFilter(val) {
  //     return val ? "二级" : "一级";
  //   },
  // },
    showNextLevel(id){
      this.parentId = id;
       this.getFenLieList();
    },
     goBackLevel() {
      this.parentId = 0;
      this.getFenLieList();
      
    },
      goCateAddPage(){
      this.$router.push("/pms/productCateAdd");
  },
    
  },
 
  mounted(){
    this.getFenLieList();
   

//   }
// }
  // mounted(){
  //     axios.get("http://yinruifang.cn/index/Api/get_product_brand_pag").then((res)=>{
  //       console.log(res)
        // this. classiFication = res.data.product
  //    })
 }
}
</script>

<style>

</style>